import sys
import os
import zipfile
import subprocess



def 解压并删除(zipfilepath):
    zipFileDirPath = os.path.dirname(zipfilepath)
    zipFilePath = zipfilepath
    
    # 解压
    with zipfile.ZipFile(file=zipFilePath,mode='r') as zip_ref:
        zip_ref.extractall(zipFileDirPath)
        print(f"压缩文件 {zipFilePath} 解压完毕!" )
        
    zip_ref.close()
    del zip_ref
    
    # 删除文件
    if(os.path.exists(zipFilePath)):
        print(f"开始删除压缩文件 : {zipFilePath}")
        os.remove(zipFilePath)
        
        if(not os.path.exists(zipFilePath)):
            print(f"压缩文件删除成功 : {zipFilePath}!")
    else:
        print("压缩文件已经删除!")
    

def 扫描压缩文件(zipfilepath):
    returnlist = []
    for root,currentdir,files in os.walk(zipfilepath):
        for file in files:
            if file.endswith(".zip"):
                returnlist.append(os.path.join(root,file))
    
    for file in returnlist:
        print(f"扫描到压缩文件 : \033[1;33;44m{file}\033[0m")
    
    return returnlist



def 执行命令(path):
    os.chdir(path)
    result = subprocess.run('cookiecutter VSCodeProjectConfig -f  --no-input', shell=True, capture_output=True, text=True)
    print(result.stdout)


if __name__ == "__main__" :
    print("=" * 50)
    print("=" * 50)
    print("=" * 50)
    print("提示 : post_gen_project.py 【Start】!\n")
    

    currentDir = os.getcwd()
    zips = 扫描压缩文件(currentDir)
    执行命令(currentDir)
    print(f"我的位置是 : {__file__}")

    
    print(f"提示 : post_gen_project.py 【End】!")
    print("=" * 50)
    print("=" * 50)
    print("=" * 50)
    print("\n\n\n\n")